#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/6/17 09:46
# @Author  : Chenmm
# @File    : user_schema.py
# @Software: PyCharm

from pydantic import BaseModel, Field, field_validator
from typing import Optional

from common.constant import SexEnum, RoleEnum
from common.json_tools import response


class UserBase(BaseModel):
    username: str = Field(min_length=8, max_length=16)
    # username: str

    # @field_validator("username")
    # def username_validator(cls, value):
    #     if len(value) < 8 or len(value) > 16:
    #         print("用户名长度不符合，长度必须在8-16之间。")
    #
    #         return response(code=100106, message="用户名长度不符合，长度必须在8-16之间。")
    #     return value



class UserCreate(UserBase):
    "用户创建验证模型"
    password: str = Field(min_length=8, max_length=16)
    role: RoleEnum
    job_num: Optional[str] = Field(None, min_length=6, max_length=10)
    student_num: Optional[str] = Field(None, min_length=12, max_length=16)
    sex: SexEnum
    age: int = Field(ge=18, le=65)
    # age: int

    # @field_validator("age")
    # def age_validator(cls, value):
    #     if value < 18 or value > 65:
    #         return response(code=100103, message="年纪大小不符合，必须在18-65之间。")
    #     return value


class UserLogin(UserBase):
    """登录校验模型"""
    password: str = Field(min_length=8, max_length=16)


class UsernameRole(UserBase):
    """校验用户登录后返回用户名及角色模型"""
    role: str


class UserChangePassword(BaseModel):
    """修改密码"""
    password: str
    new_password: str = Field(min_length=8, max_length=16)


